import { constantRoutes, asyncRoutes } from '@/router';

const state = {
  routes: constantRoutes,
};

const mutations = {
  setRoutes(state, newRoutes) {
    state.routes = [...constantRoutes, ...newRoutes];
  },
};

const actions = {
  filterRoutes(context, menus) {
    const routes = asyncRoutes.filter(v => menus.includes(v.meta.code));
    context.commit('setRoutes', routes); // 将动态路由提交给mutations
    return routes; // 这里为什么还要return  state数据 是用来 显示左侧菜单用的  return  是给路由addRoutes用的
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
